//用户id
var userid = $(".userid").text();
//添加地址
$(".insertaddress").click(function () {
    $("body").append("<form class='loginForm' action='/address/insertaddress'  name='actionForm' id='actionForm'  method='post' ><div data-v-f6440f00='' data-v-54b15c30='' class='mi-popup' style='z-index: 100;'><div data-v-f6440f00='' class='mi-popup__mask mi-modal'></div>" +
        "<div data-v-f6440f00='' class='mi-popup__box'><div data-v-f6440f00='' class='mi-popup__content'><div data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__wrapper address-modal' style='width: 660px;'><input name='userid' style='display: none' value='" + userid + "'>" +
        "<div data-v-54b15c30='' data-v-f6440f00='' aria-modal='' class='mi-dialog'><div data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__header'><span data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__title'>修改收货地址</span>" +
        "</div><a data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__headerbtn guanbi'><i data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__close iconfont'></i></a>" +
        "<div data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__body'><div class='mi-dialog__inner'><div data-v-6702e325='' class='address-add'><div data-v-6702e325='' class='item'>" +
        "<div data-v-968989be='' data-v-6702e325='' class='col mr mi-input mi-input-active '><label data-v-968989be=''  class='input-label'>姓名</label><input data-v-968989be='' type='text' name='contacts' placeholder='' value='' maxlength='' autocomplete='off' class='input-text '>" +
        "<p data-v-968989be='' class='msg msg-error' style='display: none;'></p><span data-v-968989be='' class='iconfont-circle-close icon-error' style='display: none;'></span></div>" +
        "<div data-v-968989be='' data-v-6702e325='' class='col mi-input '><label data-v-968989be='' class='input-label' style='top: -7px;font-size: 12px;'>手机号</label><input data-v-968989be='' type='text' name='phone' value='' maxlength='' autocomplete='off' class='input-text '>" +
        "<p data-v-968989be='' class='msg msg-error' style='display: none;'></p><span data-v-968989be='' class='iconfont-circle-close icon-error' style='display: none;'></span></div></div>" +
        "<div data-v-6702e325='' class='item address-info-box'><div data-v-968989be='' data-v-6702e325='' class='col mi-input mi-input-active '><label data-v-968989be=''  class='input-label'></label>" +
        "<input data-v-968989be='' type='text' name='' placeholder='选择省 / 市 / 区 / 街道' readonly='readonly' maxlength=' autocomplete='off' class='input-text show-placeholder'>" +
        "<p data-v-968989be='' class='msg msg-error' style='display: none;'></p><span data-v-968989be='' class='iconfont-circle-close icon-error' style='display: none;'></span>" +
        "</div><i data-v-6702e325='' class='iconfont iconfont-arrow-down-small'></i></div><div data-v-6702e325='' class='item'><div data-v-968989be='' data-v-6702e325='' class='col mi-input mi-input-active '>" +
        "<label data-v-968989be='' class='input-label'>详细地址</label><textarea data-v-968989be='' name='address' placeholder='详细地址，路名或街道名称，门牌号' maxlength='' autocomplete='off' class='input-text'></textarea>" +
        "<p data-v-968989be='' class='msg msg-error' style='display: none;'></p><span data-v-968989be='' class='iconfont-circle-close icon-error' style='display: none;'></span>" +
        "</div></div></div></div></div><div data-v-54b15c30='' data-v-f6440f00='' class='el-dialog__footer'><button data-v-54b15c30='' data-v-f6440f00='' class='btn btn-primary'>确定</button>" +
        "<button data-v-54b15c30='' data-v-f6440f00='' class='btn btn-gray quxiao'>取消</button></div></div></div></div></div></form>");

})
//删除地址
$(".shanchu").on('click', function() {
    var addressid = $(this).parent().parent().find(".addressid").text();
    Swal.fire({
        title: "确定删除该地址吗?",
        icon: "warning",
        confirmButtonColor: '#ff6700', // 确定按钮的 颜色
        confirmButtonText: '确定', // 确定按钮的 文字
        showCancelButton: true, // 是否显示取消按钮
        cancelButtonColor: '#b0b0b0', // 取消按钮的 颜色
        cancelButtonText: "取消", // 取消按钮的 文字
    })
        .then((isConfirm) => {
            try {
                //判断 是否 点击的 确定按钮
                if(isConfirm.value) {

                    success: {
                        icon: "success",
                            window.location.href = "/address/deleteaddress?userid="+userid+ "&addressid=" + addressid;
                    }
                } else {
                    Swal.fire("取消", "点击了取消", "error");
                }
            } catch(e) {
                alert(e);
            }
        });
});
//修改地址
$(".xiugai").click(function () {
    var addressid = $(this).parent().parent().find(".addressid").text();
    $.ajax({
        url: "/address/updateajax",
        type: "get",
        data: "addressid=" + addressid,
        dataType: "json",
        success: function (data) {
            $("body").append("<form class='loginForm' action='/address/updateaddress?addressid=" + data.addressid + "'  name='actionForm' id='actionForm'  method='post' ><div data-v-f6440f00='' data-v-54b15c30='' class='mi-popup' style='z-index: 100;'><div data-v-f6440f00='' class='mi-popup__mask mi-modal'></div>" +
                "<div data-v-f6440f00='' class='mi-popup__box'><div data-v-f6440f00='' class='mi-popup__content'><div data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__wrapper address-modal' style='width: 660px;'><input name='userid' style='display: none' value='" + data.userid + "'>" +
                "<div data-v-54b15c30='' data-v-f6440f00='' aria-modal='' class='mi-dialog'><div data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__header'><span data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__title'>修改收货地址</span>" +
                "</div><a data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__headerbtn guanbi'><i data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__close iconfont'></i></a>" +
                "<div data-v-54b15c30='' data-v-f6440f00='' class='mi-dialog__body'><div class='mi-dialog__inner'><div data-v-6702e325='' class='address-add'><div data-v-6702e325='' class='item'>" +
                "<div data-v-968989be='' data-v-6702e325='' class='col mr mi-input mi-input-active '><label data-v-968989be=''  class='input-label'>姓名</label><input data-v-968989be='' type='text' name='contacts' placeholder='' value='" + data.contacts + "' maxlength='' autocomplete='off' class='input-text '>" +
                "<p data-v-968989be='' class='msg msg-error' style='display: none;'></p><span data-v-968989be='' class='iconfont-circle-close icon-error' style='display: none;'></span></div>" +
                "<div data-v-968989be='' data-v-6702e325='' class='col mi-input '><label data-v-968989be='' class='input-label' style='top: -7px;font-size: 12px;'>手机号</label><input data-v-968989be='' type='text' name='phone' value='" + data.phone + "' maxlength='' autocomplete='off' class='input-text '>" +
                "<p data-v-968989be='' class='msg msg-error' style='display: none;'></p><span data-v-968989be='' class='iconfont-circle-close icon-error' style='display: none;'></span></div></div>" +
                "<div data-v-6702e325='' class='item address-info-box'><div data-v-968989be='' data-v-6702e325='' class='col mi-input mi-input-active '><label data-v-968989be=''  class='input-label'></label>" +
                "<input data-v-968989be='' type='text' name='' placeholder='选择省 / 市 / 区 / 街道' readonly='readonly' maxlength=' autocomplete='off' class='input-text show-placeholder'>" +
                "<p data-v-968989be='' class='msg msg-error' style='display: none;'></p><span data-v-968989be='' class='iconfont-circle-close icon-error' style='display: none;'></span>" +
                "</div><i data-v-6702e325='' class='iconfont iconfont-arrow-down-small'></i></div><div data-v-6702e325='' class='item'><div data-v-968989be='' data-v-6702e325='' class='col mi-input mi-input-active '>" +
                "<label data-v-968989be='' class='input-label'>详细地址</label><textarea data-v-968989be='' name='address' placeholder='详细地址，路名或街道名称，门牌号' maxlength='' autocomplete='off' class='input-text'>" + data.address + "</textarea>" +
                "<p data-v-968989be='' class='msg msg-error' style='display: none;'></p><span data-v-968989be='' class='iconfont-circle-close icon-error' style='display: none;'></span>" +
                "</div></div></div></div></div><div data-v-54b15c30='' data-v-f6440f00='' class='el-dialog__footer'><button data-v-54b15c30='' data-v-f6440f00='' class='btn btn-primary'>确定</button>" +
                "<button data-v-54b15c30='' data-v-f6440f00='' class='btn btn-gray quxiao'>取消</button></div></div></div></div></div></form>");
        },
        error: function (e) {
            alert("获取失败");
        }
    })
})
$(".quxiao").click(function () {
    $(".mi-popup").addClass("hide");
})
$(".guanbi").click(function () {
    $(".mi-popup").addClass("hide");
})